package com.dys.controller;

import com.dys.entity.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @className: com.dys.controller.ThymeleafController
 * @description: com.dys.controller
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/11/21 22:13
 */
@Controller
public class ThymeleafController {

    @RequestMapping(value = "/thymeleaf")
    public String thymeleaf(ModelMap map, HttpSession session) {
        map.put("thText", "th:text设置文本内容 <b>加粗</b>");
        map.put("thUText", "th:utext 设置文本内容 <b>加粗</b>");
        map.put("thValue", "thValue 设置当前元素的value值");
        map.put("thEach", "Arrays.asList(\"th:each\", \"遍历列表\")");
        map.put("thIf", "msg is not null");
        map.put("thObject", new Person("张三", 12, "男"));
        session.setAttribute("user", "大佬");
        return "thymeleaf";
    }

    @RequestMapping("standardExpression")
    public String standardExpression(ModelMap map) {
        map.put("Str", "Blog");
        map.put("Bool", true);
        map.put("Array", new Integer[]{1, 2, 3, 4});
        map.put("List", Arrays.asList(1, 3, 2, 4, 0));
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("thName", "${#...}");
        hashMap.put("desc", "变量表达式内置方法");
        map.put("Map", hashMap);
        map.put("Date", new Date());
        map.put("Num", 888.888D);
        return "standardExpression";
    }
}
